package com.mywork.mvpkodeinxml.room

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.mywork.mvpkodeinxml.app.App
import com.mywork.mvpkodeinxml.room.dao.FileCacheDao
import com.mywork.mvpkodeinxml.room.entity.FileCacheEntity

@Database(entities = [FileCacheEntity::class], version = 1, exportSchema = false)
abstract class FileCacheDatabase : RoomDatabase() {

    abstract fun fileCacheDao(): FileCacheDao

    companion object {
        private val DB_NAME = "FileCache.db"
        private var instance: FileCacheDatabase? = null

        fun getInstance(): FileCacheDatabase {
            if (instance == null) {
                instance = Room.databaseBuilder(App.instance, FileCacheDatabase::class.java, DB_NAME)
                    .allowMainThreadQueries()
                    .build()
            }
            return instance!!
        }

    }
}
